package com.pengpeng.oauth2.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.oauth2.common.DefaultOAuth2AccessToken;
import org.springframework.security.oauth2.common.OAuth2AccessToken;
import org.springframework.security.oauth2.provider.OAuth2Authentication;
import org.springframework.security.oauth2.provider.token.TokenEnhancer;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

/**
 * @author LS
 * @version 1.0
 * @description: 自定义jwt信息
 * @date 2021/4/21 上午10:16
 */
@Component
public class CustomTokenEnhancer implements TokenEnhancer {

    @Autowired
    private HttpServletRequest request;

    @Override
    public OAuth2AccessToken enhance(OAuth2AccessToken accessToken, OAuth2Authentication oAuth2Authentication) {
        Map<String, Object> additionalInfo = new HashMap<>(2);
        Map<String, String> requestParameters = oAuth2Authentication.getOAuth2Request().getRequestParameters();//端点信息
        String test = request.getHeader("test");
        additionalInfo.put("test",test);
        ((DefaultOAuth2AccessToken) accessToken).setAdditionalInformation(additionalInfo);
        return accessToken;

    }
}
